package com.youkeda.app.util;

import javax.swing.*;
import java.util.List;
import java.util.Random;

/**
 * @ClassName Demo
 * @Author 刘正星
 * @Date 2020/9/1 14:34
 **/
public class Demo {
    // 查找最长无重复字符的连续子串
    public static int findMax(String str) {
        int [] flags = new int[26];
        char [] chars = str.toCharArray();
        int front = 0;
        int rear = 0;
        int Max =0;
        while(front < str.length() && rear < str.length()){
            while(rear < str.length()){
                int index =(int)chars[rear]-97;
               // System.out.println(index);
                 if (rear == 0){
                     flags[index] = 1;
                     rear++;
                     continue;
                 }
                if (flags[index] ==1){
                    Max = Math.max(Max,rear-front);
                    int item = (int)chars[front]-97;
                    System.out.println("max="+Max);
                    System.out.println("item="+item);
                    flags[item] = 0;
                    front++;
                   continue;
                }
                rear++;
                flags[index] = 1;

            }
        }
        return Math.max(Max,rear-front);
    }

//    public static List<Double> getAmounts(double total,int numbers){
//        Random random = new Random();
//
//    }
    public static void main(String[] args) {
        String str = "ababc";
        int max = findMax(str);
        System.out.println("最长无重复字符连续子串长度：" + max);

        double random = Math.random();
        System.out.printf("%.2f",random*2.00);
    }
}
